import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes=[]
import basePermission from './baseRouter'
import hrPermissions from './hr'
import employeePermission from './employee'
import managerPermission from './manager'
import adminPermission from './admin'

routes.push(...basePermission)
const userInfo = JSON.parse(localStorage.getItem("userInfo"));
const role=userInfo? userInfo["role"]:" "

//员工权限
if(role=='employee'){
    routes.push(...employeePermission);
}
//hr权限
else if(role=='hr'){
  routes.push(...hrPermissions);
}
//部门主管权限
else if(role=='manager'){
  routes.push(...managerPermission);
}
//管理员权限
else if(role==="admin"){
  routes.push(...adminPermission);
}

//404
const NotFound=[{
  path: "/404",
  name: "NotFound",
  component:()=>import("@/views/404.vue")
}]
routes.push(...NotFound)

const router = new VueRouter({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes
});

export default router
